{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "^fill^README.md^here^\n",
    "\n",
    "- - -"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "^fill^theory.md^here^\n",
    "\n",
    "- - -"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Demonstration"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### 1. Library imports"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "Import libraries needed by the calculation. The external libraries used are:\n",
    "\n",
    "- [numpy](http://www.numpy.org/)\n",
    "\n",
    "- [DataModelDict](https://github.com/usnistgov/DataModelDict)\n",
    "\n",
    "- [atomman](https://github.com/usnistgov/atomman)\n",
    "\n",
    "- [iprPy](https://github.com/usnistgov/iprPy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "# Standard library imports\n",
    "from __future__ import division, absolute_import, print_function\n",
    "import os\n",
    "import sys\n",
    "import uuid\n",
    "import glob\n",
    "import shutil\n",
    "import random\n",
    "import datetime\n",
    "from copy import deepcopy\n",
    "\n",
    "# http://www.numpy.org/\n",
    "import numpy as np \n",
    "\n",
    "# https://github.com/usnistgov/DataModelDict \n",
    "from DataModelDict import DataModelDict as DM\n",
    "\n",
    "# https://github.com/usnistgov/atomman \n",
    "import atomman as am\n",
    "import atomman.lammps as lmp\n",
    "import atomman.unitconvert as uc\n",
    "\n",
    "# https://github.com/usnistgov/iprPy\n",
    "import iprPy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### 2. Assign values for the calculation's run parameters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.0 Set the calculation's working directory"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "calc_name = 'dislocation_monopole'\n",
    "\n",
    "# Check current working directory\n",
    "cwd_name = os.path.basename(os.getcwd())\n",
    "\n",
    "# Change working directory if needed\n",
    "if cwd_name != calc_name:\n",
    "    if not os.path.isdir(calc_name):\n",
    "        os.mkdir(calc_name)\n",
    "    os.chdir(calc_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.1 Specify system-specific paths\n",
    "\n",
    "Simple input parameters:\n",
    "\n",
    "- __lammps_command__ is the LAMMPS command to use.\n",
    "\n",
    "- __mpi_command__ MPI command for running LAMMPS in parallel. A value of None will run simulations serially.\n",
    "\n",
    "- __lib_directory__ defines the relative path to the iprPy library. This makes it easier to define paths to reference records later."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "lammps_command = 'lmp_mpi'\n",
    "mpi_command = 'mpiexec -localonly 4'\n",
    "lib_directory = '../../../library'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.2 Specify the potenital and elemental symbols\n",
    "\n",
    "Simple input parameters:\n",
    "\n",
    "- __potential_name__ gives the name of the potential_LAMMPS reference record in the iprPy library to use for potential. \n",
    "\n",
    "- __symbols__ is a list of the elemental model symbols of potential to associate with the unique atom types of system.\n",
    "\n",
    "Derived parameters:\n",
    "\n",
    "- __potential_dir_path__ gives the path for the folder containing the artifacts associated with the potential (i.e. eam.alloy file). If an empty string '' is given, the necessary artifacts are taken as being in the working directory. (Here, it is derived from lib_directory and potential_name.)\n",
    "\n",
    "- __potential_path__ gives the path to the potential_LAMMPS reference record to use. (Here, it is derived from lib_directory and potential_name.)\n",
    "\n",
    "- __potential__ is the atomman.lammps.Potential representation of a LAMMPS implemented potential to use. (Here, the class is implemented using potential_path and potential_dir_path.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Successfully loaded potential 1999--Mishin-Y--Ni--LAMMPS--ipr1\n"
     ]
    }
   ],
   "source": [
    "potential_name = '1999--Mishin-Y--Ni--LAMMPS--ipr1'\n",
    "symbols = ['Ni']\n",
    "\n",
    "# -------------- Derived parameters -------------- #\n",
    "# Define potential_path and potential_dir_path using lib_directory and potential_name\n",
    "potential_dir_path = os.path.abspath(os.path.join(lib_directory, 'potential_LAMMPS', potential_name))\n",
    "potential_path = potential_dir_path + '.json'\n",
    "\n",
    "# Create potential by loading LAMMPS-potential record\n",
    "potential = lmp.Potential(potential_path, potential_dir_path)\n",
    "\n",
    "print('Successfully loaded potential', potential)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.3 Specify the prototype unit cell system\n",
    "\n",
    "Simple input parameters:\n",
    "\n",
    "- __prototype_name__ gives the name of the crystal_prototype reference record in the iprPy library to use for ucell. \n",
    "\n",
    "- __box_parameters__ defines the box parameters to scale ucell to. This is a list of either three or six floats\n",
    "    - __[a, b, c]__ are the orthogonal lattice parameters in length units.\n",
    "    - __[a, b, c, alpha, beta, gamma]__ are the triclinic lattice parameters in length units and angles in degrees.\n",
    "\n",
    "Derived parameters:\n",
    "\n",
    "- __prototype_path__ gives the path to the crystal_prototype reference record to use. (Here, it is derived from lib_directory and prototype_name).\n",
    "\n",
    "- __ucell__ is an atomman.System representing a fundamental unit cell of the system. (Here, it is loaded from prototype_path file, then scaled using box_parameters)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 3.520,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  3.520,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  3.520]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 4\n",
      "natypes = 1\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   0.000 |   0.000 |   0.000\n",
      "      1 |       1 |   0.000 |   1.760 |   1.760\n",
      "      2 |       1 |   1.760 |   0.000 |   1.760\n",
      "      3 |       1 |   1.760 |   1.760 |   0.000\n"
     ]
    }
   ],
   "source": [
    "prototype_name = 'A1--Cu--fcc'\n",
    "box_parameters = uc.set_in_units([3.52, 3.52, 3.52], 'angstrom')\n",
    "\n",
    "# -------------- Derived parameters -------------- #\n",
    "# Define prototype_path using lib_directory and prototype_name\n",
    "prototype_path = os.path.abspath(os.path.join(lib_directory, 'crystal_prototype', prototype_name+'.json'))\n",
    "\n",
    "# Create ucell by loading prototype record\n",
    "ucell = am.load('system_model', prototype_path)[0]\n",
    "\n",
    "# Rescale ucell using box_parameters\n",
    "if len(box_parameters) == 3:\n",
    "    ucell.box_set(a=box_parameters[0], b=box_parameters[1], c=box_parameters[2], scale=True)\n",
    "elif len(box_parameters) == 6:\n",
    "    ucell.box_set(a=box_parameters[0], b=box_parameters[1], c=box_parameters[2], scale=True,\n",
    "                  alpha=box_parameters[3], beta=box_parameters[4], gamma=box_parameters[5])\n",
    "\n",
    "print(ucell)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.4 Specify material elastic constants\n",
    "\n",
    "Simple input parameters:\n",
    "\n",
    "- __C_dict__ is a dictionary containing the unique elastic constants for the potential and crystal structure defined above. \n",
    "\n",
    "Derived parameters\n",
    "\n",
    "- __C__ is an atomman.ElasticConstants object built from C_dict."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "C_dict = {}\n",
    "C_dict['C11'] = uc.set_in_units(247.86, 'GPa')\n",
    "C_dict['C12'] = uc.set_in_units(147.83, 'GPa')\n",
    "C_dict['C44'] = uc.set_in_units(124.84, 'GPa')\n",
    "\n",
    "# -------------- Derived parameters -------------- #\n",
    "# Build ElasticConstants object from C_dict terms\n",
    "C = am.ElasticConstants(**C_dict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.5 Specify the defect \n",
    "\n",
    "Simple input parameters:\n",
    "\n",
    "- __dislocation_name__ gives the name of the dislocation_monopole reference record in the iprPy library to use for potential. \n",
    "\n",
    "Derived parameters:\n",
    "\n",
    "- __dislocation_path__ gives the path to the dislocation_monopole reference record to use. (Here, it is derived from lib_directory and dislocation_name).\n",
    "\n",
    "- __dislocation_model__ is a DataModelDict of a dislocation_monopole record. (Here, the dislocation_path file is loaded as a DataModelDict.)\n",
    "\n",
    "- __dislocation_kwargs__ is a dictionary containing parameters for generating the defect. Values are extracted from the dislocation_model record and uniquely define a type of stacking fault. Included keywords are:\n",
    "\n",
    "    - __burgers__ is the crystallographic Burgers vector for the dislocation\n",
    "    \n",
    "    - __crystallographic-axes__ specifies how to orient the system. Subelements define each of the x-, y-, and z-axes.\n",
    "    \n",
    "    - __atomshift__ is a 3D vector rigid-body shift to apply to atoms in the system. The atomshift vector is relative to the rotated unit cell's box vectors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Successfully loaded defect record for A1--Cu--fcc--111-edge\n",
      "{\n",
      "    \"x_axis\": \" 1  0 -1\", \n",
      "    \"y_axis\": \" 1  1  1\", \n",
      "    \"z_axis\": \" 1 -2  1\", \n",
      "    \"atomshift\": \" 0.00 0.25 0.00\", \n",
      "    \"burgersvector\": \" 0.5  0.0 -0.5\"\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "dislocation_name = 'A1--Cu--fcc--111-edge'\n",
    "\n",
    "# -------------- Derived parameters -------------- #\n",
    "# Define dislocation_path using lib_directory and dislocation_name\n",
    "dislocation_path = os.path.abspath(os.path.join(lib_directory, 'dislocation_monopole', dislocation_name+'.json')) \n",
    "\n",
    "# Load dislocation-monopole record as a DataModelDict\n",
    "with open(dislocation_path) as f:\n",
    "    dislocation_model = DM(f)\n",
    "\n",
    "print('Successfully loaded defect record for', dislocation_model['dislocation-monopole']['id'])\n",
    "\n",
    "# Extract defect parameters    \n",
    "dislocation_kwargs = dislocation_model['dislocation-monopole']['calculation-parameter']\n",
    "\n",
    "print(dislocation_kwargs.json(indent=4))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.6 Generate the initial system\n",
    "\n",
    "Simple input parameters:\n",
    "\n",
    "- __sizemults__ list of three integers or three tuple pairs of integers specifying how many times (and in which direction) the ucell vectors of $a$, $b$ and $c$ are replicated in creating system.\n",
    "\n",
    "Defect model parameters:\n",
    "\n",
    "- __x_axis__ is the 3D crystal vector relative to ucell to align with the x-axis of system.\n",
    "\n",
    "- __y_axis__ is the 3D crystal vector relative to ucell to align with the y-axis of system.\n",
    "\n",
    "- __z_axis__ is the 3D crystal vector relative to ucell to align with the z-axis of system.\n",
    "\n",
    "- __atomshift__ is a 3D vector rigid-body shift to apply to atoms in the system. The atomshift vector is relative to the rotated unit cell's box vectors.\n",
    "\n",
    "Derived parameters:\n",
    "\n",
    "- __axes__ is a 3x3 array combining x_axis, y_axis and z_axis.\n",
    "\n",
    "- __shift__ is a 3D vector rigid-body shift to apply to atoms in the system. The shift vector is in absolute Cartesian units. (Here, it is derived from atomshift).\n",
    "\n",
    "- __system__ is the base atomman.System to use. (Here, it is derived by copying ucell, rotating according to axes, applying shift, then sizemults"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# of atoms in system = 34560\n"
     ]
    }
   ],
   "source": [
    "sizemults = [(-15,15), (-12,12), (0,2)]\n",
    "\n",
    "# -------------- Defect parameters --------------- #\n",
    "x_axis = np.array(dislocation_kwargs['x_axis'].split(), dtype=float)\n",
    "y_axis = np.array(dislocation_kwargs['y_axis'].split(), dtype=float)\n",
    "z_axis = np.array(dislocation_kwargs['z_axis'].split(), dtype=float)\n",
    "atomshift = np.array(dislocation_kwargs['atomshift'].split(), dtype=float)\n",
    "\n",
    "# -------------- Derived parameters -------------- #\n",
    "# Copy ucell to initialsystem\n",
    "system = deepcopy(ucell)\n",
    "\n",
    "# Build axes from x_axis, y_axis and z_axis\n",
    "axes = np.array([x_axis, y_axis, z_axis])\n",
    "\n",
    "# Rotate using axes\n",
    "system = am.rotate_cubic(system, axes)\n",
    "\n",
    "# Convert atomshift to shift using the rotated system\n",
    "shift = (atomshift[0] * system.box.avect \n",
    "         + atomshift[1] * system.box.bvect \n",
    "         + atomshift[2] * system.box.cvect)\n",
    "\n",
    "# Apply shift\n",
    "system.atoms_prop(key='pos', value=system.atoms_prop(key='pos') + shift)\n",
    "\n",
    "# Apply sizemults\n",
    "system.supersize(*sizemults)\n",
    "\n",
    "print('# of atoms in system =', system.natoms)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 2.7 Specify calculation-specific run parameters\n",
    "\n",
    "Simple input parameters:\n",
    "\n",
    "- __boundarywidth__ sets the minimum width of the fixed-atom boundary region. This is taken in units of the a lattice parameter of the unit cell.\n",
    "\n",
    "- __boundaryshape__ specifies what shape to make the fixed-atom boundary region.\n",
    "\n",
    "    - __circle__ will create a cylindrical active region.\n",
    "    \n",
    "    - __rect__ will create a rectangular active region.\n",
    "\n",
    "- __annealtemperature__ is the temperature at which to relax (anneal) the dislocation system. If annealtemperature is 0.0, then only a static relaxation will be performed. Default value is 0.0.\n",
    "\n",
    "- __randomseed__ allows for the random seed used in generating initial atomic velocities for a dynamic relaxation to be specified. This is an integer between 1 and 900000000. Default value is None, which will randomly pick a number in that range.\n",
    "\n",
    "- __energytolerance__ is the energy tolerance to use during the minimizations. This is unitless.\n",
    "\n",
    "- __forcetolerance__ is the force tolerance to use during the minimizations. This is in energy/length units.\n",
    "\n",
    "- __maxiterations__ is the maximum number of minimization iterations to use.\n",
    "\n",
    "- __maxevaluations__ is the maximum number of minimization evaluations to use.\n",
    "\n",
    "- __maxatommotion__ is the largest distance that an atom is allowed to move during a minimization iteration. This is in length units. \n",
    "\n",
    "Defect model parameters\n",
    "\n",
    "- __burgersvector__ defines the crystallographic Burgers vector for the dislocation being added.\n",
    "\n",
    "Derived parameters\n",
    "\n",
    "- __T__ is the transformation matrix associated with axes.\n",
    "\n",
    "- __bwidth__ is the minimum boundary width in length units. This is obtained by scaling boundarywidth by the $a$ unit cell box vector.\n",
    "\n",
    "- __burgers__ is the Burgers vector in absolute Cartesian units. This is obtained by scaling dislocation_burgersvector by the unit cell box vectors, and then transforming to the defined axes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "boundarywidth = 3\n",
    "boundaryshape = 'circle'\n",
    "\n",
    "annealtemperature = 0.0\n",
    "randomseed = None\n",
    "\n",
    "energytolerance = 0.0\n",
    "forcetolerance = uc.set_in_units(1e-6, 'eV/angstrom')\n",
    "maxiterations = 10000\n",
    "maxevaluations = 100000\n",
    "maxatommotion = uc.set_in_units(0.01, 'angstrom')\n",
    "\n",
    "# -------------- Defect parameters --------------- #\n",
    "burgersvector = np.array(dislocation_kwargs['burgersvector'].split(), float)\n",
    "\n",
    "# -------------- Derived parameters -------------- #\n",
    "# Scale and transform the Burgers vector\n",
    "T = am.tools.axes_check(axes)\n",
    "burgers = T.dot(burgersvector[0] * ucell.box.avect + \n",
    "                burgersvector[1] * ucell.box.bvect + \n",
    "                burgersvector[2] * ucell.box.cvect)\n",
    "# Scale boundary width\n",
    "bwidth = ucell.box.a * boundarywidth"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### 3. Define calculation function(s) and generate template LAMMPS script(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 3.1 disl_relax.template"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "with open('disl_relax.template', 'w') as f:\n",
    "    f.write(\"\"\"^fill^disl_relax.template^here^\"\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 3.2 dislocationmonopole()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "^fill^calc_dislocation_monopole.py(dislocationmonopole)^here^"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 3.3 disl_boundary_fix()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "^fill^calc_dislocation_monopole.py(disl_boundary_fix)^here^"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 3.4 disl_relax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "^fill^calc_dislocation_monopole.py(disl_relax)^here^"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 3.5 anneal_info() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "^fill^calc_dislocation_monopole.py(anneal_info)^here^"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### 4. Run calculation function(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "results_dict = dislocationmonopole(lammps_command, \n",
    "                                   system, \n",
    "                                   potential,\n",
    "                                   symbols,  \n",
    "                                   burgers,\n",
    "                                   C,\n",
    "                                   axes = axes,\n",
    "                                   mpi_command = mpi_command,\n",
    "                                   etol = energytolerance,\n",
    "                                   ftol = forcetolerance,\n",
    "                                   maxiter = maxiterations,\n",
    "                                   maxeval = maxevaluations,\n",
    "                                   dmax = maxatommotion,\n",
    "                                   annealtemp = annealtemperature, \n",
    "                                   randomseed = randomseed, \n",
    "                                   bwidth = bwidth, \n",
    "                                   bshape = boundaryshape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['symbols_disl',\n",
       " 'Stroh_K_tensor',\n",
       " 'symbols_base',\n",
       " 'E_total_disl',\n",
       " 'Stroh_preln',\n",
       " 'dumpfile_base',\n",
       " 'dumpfile_disl']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results_dict.keys()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### 5. Report results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 5.1 Define units for outputting values\n",
    "\n",
    "- __length_unit__ is the unit of length to display results in.\n",
    "- __energy_unit__ is the unit of energy to display cohesive energies in.\n",
    "- __e_A_unit__ is the energy per area to report the surface energy in."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "outputs": [],
   "source": [
    "length_unit = 'angstrom'\n",
    "energy_unit = 'eV'\n",
    "pressure_unit = 'GPa'\n",
    "e_l_unit = energy_unit+'/'+length_unit"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 5.2 Print Stroh method parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pre-ln factor (alpha) = 0.344228972217 eV/angstrom\n",
      "K_tensor =\n",
      "[[ 123.86918865    0.            0.        ]\n",
      " [   0.          127.31323026  -12.76027037]\n",
      " [   0.          -12.76027037   81.07544348]] GPa\n"
     ]
    }
   ],
   "source": [
    "print('pre-ln factor (alpha) =', uc.get_in_units(results_dict['Stroh_preln'], e_l_unit), e_l_unit)\n",
    "print('K_tensor =')\n",
    "print(uc.get_in_units(results_dict['Stroh_K_tensor'], pressure_unit), pressure_unit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "deletable": true,
    "editable": true
   },
   "source": [
    "#### 5.3 List dump files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Perfect system is saved as base.dump\n",
      "Defect system is saved as disl.dump\n"
     ]
    }
   ],
   "source": [
    "print('Perfect system is saved as', results_dict['dumpfile_base'])\n",
    "print('Defect system is saved as',  results_dict['dumpfile_disl'])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
